using System;
using System.Collections;

namespace Curriculum.Utiles
{
	/// <summary>
	/// Summary description for ListaAbstracta.
	/// </summary>
	public abstract class ListaAbstracta : ICollection, IList
	{
		protected ArrayList lista = new ArrayList();

		public ListaAbstracta()
		{}


		protected abstract Type GetTipoElemento();

		public void SetPosition(int i, object valor)
		{
			this.ValidarTipo(valor);
			this.lista[i]=valor;
		}

		public object GetValue(int index)
		{
			try
			{
				return this.lista[index];
			}
			catch
			{
				return null;
			}
		}

		protected void ValidarTipo(object valor)
		{
			if (GetTipoElemento() != valor.GetType())
			{
				throw(new System.Exception( "el objeto recibido no es de tipo "+ GetTipoElemento().ToString()));
			}
		}
		
		

		#region IList

		// accessor
		public object this[int index]
		{
			get
			{
				return lista[index];
			}
			set
			{
				this.lista[index] = value;
			}
		}

		public int Add(object valor)
		{
			this.ValidarTipo(valor);
			return this.lista.Add(valor);
		}

		public void Add(ListaAbstracta valores)
		{
			foreach (object obj in valores)
			{
				this.Add(obj);
			}
		}

		public bool Contains(object value)
		{
			return this.lista.Contains(value);
		}

		public void Clear()
		{
			this.lista.Clear();
		}

		public int IndexOf(object value)
		{
			return this.lista.IndexOf(value);
		}

		public void Insert(int index, object value)
		{
			this.lista.Insert(index, value);
		}
	
		public void Remove(object valor)
		{
			this.lista.Remove(valor);
		}

		public void RemoveAt(int index)
		{
			this.lista.RemoveAt(index);
		}

		public bool IsReadOnly
		{
			get { return this.lista.IsReadOnly; }
		}

		public bool IsFixedSize
		{
			get { return this.lista.IsFixedSize; }
		}


		#endregion 

		#region ICollection Members

		public bool IsSynchronized
		{
			get
			{
				return this.lista.IsSynchronized;
			}
		}

		public int Count
		{
			get
			{
				return this.lista.Count;
			}
		}

		public void CopyTo(System.Array array, int index)
		{
			this.lista.CopyTo(array, index);
		}

		public object SyncRoot
		{
			get
			{
				return this.lista.SyncRoot;
			}
		}	

		#endregion

		#region IEnumerable Members

		public IEnumerator GetEnumerator()
		{
			return this.lista.GetEnumerator();
		}

		#endregion
	}
}
